import ReactDOM from "react-dom/client";
import App from "./App.tsx";
import "./index.scss";
import { ConfigProvider } from "antd";
//引入路由
import { RouterProvider, createHashRouter, Navigate } from "react-router-dom";
//antd中文化
import "dayjs/locale/zh-cn";
import zhCN from "antd/locale/zh_CN";
//全局配置，context上下文
//import AppProvider, { routeData } from "./component/AppProvider.tsx";
import { Provider } from "react-redux";
import store from "./store/store.ts";
import Login from "./page/Login.tsx";
import Home from "./page/Home.tsx";
import SwipeList from "./page/Swipe/SwipeList.tsx";
import Index from "./page/Swipe/index.tsx";
import Users from "./page/User/users.tsx";
import Manages from "./page/User/manages.tsx";
import User from "./page/User/index.tsx";
import Shop from "./page/Shop";
import ShopList from "./page/Shop/ShopList.tsx";
import ShopSort from "./page/Shop/ShopSort.tsx";
import { getToken } from "./utils/tools.ts";
import Order from "./page/Order";
//配置路由
const router = createHashRouter([
  {
    path: "/login",
    element: <Login />,
  },
  {
    path: "/",
    //判断本地是否有token值，没有的话直接跳到登录页
    element: getToken() ? <App /> : <Navigate to="/login" />,
    //element: <App />,
    children: [
      {
        path: "home",
        element: <Home />,
      },
      {
        // 轮播图管理
        path: "swipe",
        element: <Index />,
        children: [
          {
            //轮播图列表
            path: "/swipe/swipelist",
            element: <SwipeList />,
          },
        ],
      },
      {
        //账户管理
        path: "user",
        element: <User />,
        children: [
          {
            //用户列表
            path: "/user/users",
            element: <Users />,
          },
          {
            //管理者
            path: "/user/manages",
            element: <Manages />,
          },
        ],
      },
      {
        //商品管理
        path: "shop",
        element: <Shop />,
        children: [
          {
            //商品列表
            path: "/shop/shoplist",
            element: <ShopList />,
          },
          {
            //商品分类
            path: "/shop/shopsort",
            element: <ShopSort />,
          },
        ],
      },
      {
        //订单管理
        path: "/order",
        element: <Order />,
      },
    ],
  },
]);
ReactDOM.createRoot(document.getElementById("root") as HTMLElement).render(
  <ConfigProvider locale={zhCN}>
    <Provider store={store}>
      <RouterProvider router={router} />
    </Provider>
  </ConfigProvider>
);
